const Mock = require('mockjs')
const Random = Mock.Random

let Result = {
  code: 200,
  msg: 'success',
  data: null
}

// 存储当前验证码
let currentCaptcha = '';

// 随机获取图片
Mock.mock('/getPic', 'get', ()=>{
  // 生成包含数字和字母的随机验证码（4-6位）
  currentCaptcha = Random.string('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 4, 6);
  
  Result.data = {
    img: Random.dataImage('120x40', currentCaptcha),
    captcha: currentCaptcha // 开发环境下可以返回验证码，生产环境应移除
  };
  return Result
})

// 验证码校验接口
Mock.mock('/verifyCaptcha', 'post', (options) => {
  const body = JSON.parse(options.body);
  const userCaptcha = body.captcha;
  
  if (userCaptcha && userCaptcha.toLowerCase() === currentCaptcha.toLowerCase()) {
    Result.code = 200;
    Result.msg = '验证码正确';
  } else {
    Result.code = 400;
    Result.msg = '验证码错误';
  }
  
  return Result;
});

// 模拟艺人数据
let artistInfo = [
  {
    id: 1,
    name: '周杰伦',
    status: '巡演中',
    fansCount: 50000000,
    fansIncreaseLast30Days: 25000,
    revenueLast30Days: 5000000,
    contractRemainingDays: 365,
    baseCity: '台北'
  },
  {
    id: 2,
    name: '林俊杰',
    status: '休息中',
    fansCount: 30000000,
    fansIncreaseLast30Days: -1500,
    revenueLast30Days: 3000000,
    contractRemainingDays: 45,
    baseCity: '新加坡'
  },
  {
    id: 3,
    name: '薛之谦',
    status: '创作中',
    fansCount: 25000000,
    fansIncreaseLast30Days: 10000,
    revenueLast30Days: 2000000,
    contractRemainingDays: 180,
    baseCity: '上海'
  },
  {
    id: 4,
    name: '华晨宇',
    status: '休息中',
    fansCount: 20000000,
    fansIncreaseLast30Days: -2000,
    revenueLast30Days: -150000,
    contractRemainingDays: 30,
    baseCity: '北京'
  },
  {
    id: 5,
    name: '张艺兴',
    status: '巡演中',
    fansCount: 18000000,
    fansIncreaseLast30Days: 5000,
    revenueLast30Days: 1500000,
    contractRemainingDays: 220,
    baseCity: '长沙'
  },
  {
    id: 6,
    name: '邓紫棋',
    status: '休息中',
    fansCount: 15000000,
    fansIncreaseLast30Days: -3000,
    revenueLast30Days: -200000,
    contractRemainingDays: 50,
    baseCity: '香港'
  },
  {
    id: 7,
    name: '鹿晗',
    status: '签约中',
    fansCount: 28000000,
    fansIncreaseLast30Days: 8000,
    revenueLast30Days: 800000,
    contractRemainingDays: 0,
    baseCity: '北京'
  },
  {
    id: 8,
    name: 'TFBOYS',
    status: '创作中',
    fansCount: 23000000,
    fansIncreaseLast30Days: 3500,
    revenueLast30Days: 1200000,
    contractRemainingDays: 150,
    baseCity: '北京'
  },
  {
    id: 9,
    name: '王嘉尔',
    status: '巡演中',
    fansCount: 16000000,
    fansIncreaseLast30Days: 7000,
    revenueLast30Days: 1800000,
    contractRemainingDays: 280,
    baseCity: '香港'
  },
  {
    id: 10,
    name: '李宇春',
    status: '休息中',
    fansCount: 14000000,
    fansIncreaseLast30Days: -1200,
    revenueLast30Days: 900000,
    contractRemainingDays: 90,
    baseCity: '成都'
  },
  {
    id: 11,
    name: '蔡徐坤',
    status: '签约中',
    fansCount: 12000000,
    fansIncreaseLast30Days: -5000,
    revenueLast30Days: -300000,
    contractRemainingDays: 0,
    baseCity: '北京'
  },
  {
    id: 12,
    name: '毛不易',
    status: '创作中',
    fansCount: 9000000,
    fansIncreaseLast30Days: 4000,
    revenueLast30Days: 600000,
    contractRemainingDays: 210,
    baseCity: '哈尔滨'
  },
  {
    id: 13,
    name: '杨幂',
    status: '休息中',
    fansCount: 35000000,
    fansIncreaseLast30Days: -10000,
    revenueLast30Days: -500000,
    contractRemainingDays: 40,
    baseCity: '北京'
  },
  {
    id: 14,
    name: '周深',
    status: '巡演中',
    fansCount: 11000000,
    fansIncreaseLast30Days: 15000,
    revenueLast30Days: 2500000,
    contractRemainingDays: 300,
    baseCity: '贵阳'
  },
  {
    id: 15,
    name: 'R1SE',
    status: '签约中',
    fansCount: 8000000,
    fansIncreaseLast30Days: -12000,
    revenueLast30Days: -800000,
    contractRemainingDays: 0,
    baseCity: '上海'
  }
]

// 模拟显示艺人信息
// Mock.mock('/getArtistInfo', 'get', ()=>{
//   Result.data = artistInfo
//   return Result
// })

// 模拟添加艺人
// Mock.mock('/addArtist', 'post', (options) => {
//   // 解析请求体
//   const body = JSON.parse(options.body);
  
//   // 生成新 ID (取当前最大 ID + 1)
//   const newId = Math.max(...artistInfo.map(artist => artist.id)) + 1;
  
//   // 创建新艺人对象
//   const newArtist = {
//     id: newId,
//     name: body.name,
//     status: body.status,
//     fansCount: Number(body.fansCount) || 0,
//     fansIncreaseLast30Days: Number(body.fansIncreaseLast30Days) || 0,
//     revenueLast30Days: Number(body.revenueLast30Days) || 0,
//     contractRemainingDays: Number(body.contractRemainingDays) || 0,
//     baseCity: body.baseCity || ''
//   };
  
//   // 添加到艺人列表
//   artistInfo.push(newArtist);
  
//   Result.msg = '添加艺人成功';
//   return Result;
// });

// 模拟修改艺人
// Mock.mock(new RegExp('/updateArtist/\\d+'), 'put', (options) => {
//   // 获取艺人 ID
//   const id = parseInt(options.url.match(/\/updateArtist\/(\d+)/)[1]);
  
//   // 解析请求体
//   const body = JSON.parse(options.body);
  
//   // 查找艺人
//   const index = artistInfo.findIndex(artist => artist.id === id);
  
//   if (index !== -1) {
//     // 更新艺人信息
//     artistInfo[index] = {
//       ...artistInfo[index],
//       name: body.name,
//       status: body.status,
//       fansCount: Number(body.fansCount),
//       fansIncreaseLast30Days: Number(body.fansIncreaseLast30Days),
//       revenueLast30Days: Number(body.revenueLast30Days),
//       contractRemainingDays: Number(body.contractRemainingDays),
//       baseCity: body.baseCity
//     };
    
//     Result.msg = '修改艺人成功';
//   } else {
//     Result.code = 404;
//     Result.msg = '未找到该艺人';
//   }
  
//   return Result;
// });

// 模拟删除艺人
// Mock.mock(new RegExp('/deleteArtist/\\d+'), 'delete', (options) => {
//   // 获取艺人 ID
//   const id = parseInt(options.url.match(/\/deleteArtist\/(\d+)/)[1]);
  
//   // 查找艺人
//   const index = artistInfo.findIndex(artist => artist.id === id);
  
//   if (index !== -1) {
//     // 删除艺人
//     artistInfo.splice(index, 1);
    
//     Result.msg = '删除艺人成功';
//   } else {
//     Result.code = 404;
//     Result.msg = '未找到该艺人';
//   }
  
//   return Result;
// });

// 模拟获取30天趋势数据
Mock.mock('/getTrendData', 'get', () => {
  const dates = [];
  const followers = [];
  const revenue = [];
  
  const now = new Date();
  for (let i = 29; i >= 0; i--) {
    const date = new Date(now);
    date.setDate(now.getDate() - i);
    dates.push(`${date.getMonth() + 1}/${date.getDate()}`);
    
    // 生成随机波动的粉丝和营收数据
    const baseFollowers = 320000 + Math.random() * 50000;
    const baseRevenue = 150000 + Math.random() * 30000;
    
    // 添加一些趋势变化
    const trend = Math.sin(i / 5) * 20000;
    
    followers.push(Math.round(baseFollowers + trend));
    revenue.push(Math.round(baseRevenue + trend * 0.5));
  }
  
  Result.data = {
    dates,
    followers,
    revenue
  };
  
  return Result;
});

// 模拟获取近期活动数据
Mock.mock('/getRecentActivities', 'get', () => {
  const activities = [
    {
      id: 1,
      title: '周杰伦新专辑发布会',
      type: 'album',
      date: '2023-05-15',
      importance: 'high',
      status: 'upcoming'
    },
    {
      id: 2,
      title: '林俊杰合约续签',
      type: 'contract',
      date: '2023-05-10',
      importance: 'high',
      status: 'completed'
    },
    {
      id: 3,
      title: '薛之谦巡演北京站',
      type: 'concert',
      date: '2023-05-20',
      importance: 'medium',
      status: 'upcoming'
    },
    {
      id: 4,
      title: '华晨宇新歌上线',
      type: 'song',
      date: '2023-05-05',
      importance: 'medium',
      status: 'completed'
    },
    {
      id: 5,
      title: '张艺兴综艺录制',
      type: 'variety',
      date: '2023-05-18',
      importance: 'low',
      status: 'upcoming'
    },
    {
      id: 6,
      title: '邓紫棋商业代言签约',
      type: 'endorsement',
      date: '2023-05-25',
      importance: 'medium',
      status: 'upcoming'
    }
  ];
  
  Result.data = activities;
  return Result;
});

let DOUDOUschedulelist=[
  {
      id:1,
      date:'2025.04.19',
      name:'「星降ル夜ノ祈リ」DOUDOU 日本公演',
      address:'东京 代官山UNIT',
      startime:'19:00',
      endtime:'21:00',
      duration:'120'
  },{
      id:2,
      date:"2025.05.03",
      name:"北京超级草莓音乐节",
      address:"北京世园公园飞行营地",
      startime:'15:25',
      endtime:'16:05',
      duration:'40'
  }
];

// Mock.mock('/getDOUDOUschedule','get',()=>{
//   Result.data=DOUDOUschedulelist;
//   return Result;
// })

// Mock.mock(new RegExp('/deleteDOUDOUschedule/\\d+'), 'delete', (options) => {
//   // 获取艺人 ID
//   const id = parseInt(options.url.match(/\/deleteDOUDOUschedule\/(\d+)/)[1]);
  
//   // 查找艺人
//   const index = DOUDOUschedulelist.findIndex(DOUDOUschedule => DOUDOUschedule.id === id);
  
//   if (index !== -1) {
//     // 删除艺人
//     DOUDOUschedulelist.splice(index, 1);
//     Result.msg = '删除行程成功';
//   } else {
//     Result.code = 404;
//     Result.msg = '未找到该行程';
//   }
  
//   return Result;
// });

// Mock.mock(new RegExp('/updateDOUDOUSchedule/\\d+'), 'put', (options) => {
//   const id = parseInt(options.url.match(/\d+/)[0])
//   const body = JSON.parse(options.body)
  
//   // 查找并更新数据
//   const index = DOUDOUschedulelist.findIndex(item => item.id === id)
//   if (index !== -1) {
//     DOUDOUschedulelist[index] = {
//       ...DOUDOUschedulelist[index],
//       date: body.date,
//       name: body.name,
//       address: body.address,
//       startime: body.startime,
//       endtime: body.endtime,
//       duration: body.duration // 自动计算
//     }
//     return { code: 200, msg: '修改成功' }
//   }
//   return { code: 404, msg: '未找到该行程' }
// })



// Mock.mock('/addDOUDOUSchedule', 'post', (options) => {
//   // 解析请求体
//   const body = JSON.parse(options.body);
  
//   // 生成新 ID (取当前最大 ID + 1)
//   const newId = Math.max(...DOUDOUschedulelist.map(DOUDOUschedule => DOUDOUschedule.id)) + 1;
  
//   // 创建新艺人对象
//   const newDOUDOUSchedule = {
//     id: newId,
//     date: body.date,
//     name: body.name,
//     address:body.address,
//     startime:body.startime,
//     endtime:body.endtime,
//     duration: body.duration
//   };
  
//   // 添加到艺人列表
//   DOUDOUschedulelist.push(newDOUDOUSchedule);
  
//   Result.msg = '添加艺人成功';
//   return Result;
// });

let worksData = [
  {
    id: 1,
    title: '南三环东路',
    type: 'single',
    releaseDate: '2023-05-01',
    link: 'https://example.com/track1'
  },
  {
    id: 2,
    title: '我用什么把你留住',
    type: 'album',
    releaseDate: '2023-06-15',
    link: 'https://example.com/album1'
  }
];

// 获取作品列表
// Mock.mock('/api/works', 'get', () => {
//   return {
//     code: 200,
//     msg: 'success',
//     data: worksData
//   };
// });

// // 新增作品
// Mock.mock('/api/works', 'post', (options) => {
//   const newWork = JSON.parse(options.body);
//   newWork.id = Math.max(...worksData.map(w => w.id)) + 1;
//   worksData.push(newWork);
//   return {
//     code: 200,
//     msg: '新增成功',
//     data: newWork
//   };
// });

// // 修改作品
// Mock.mock(new RegExp('/api/works/\\d+'), 'put', (options) => {
//   const id = parseInt(options.url.match(/\/api\/works\/(\d+)/)[1]);
//   const index = worksData.findIndex(w => w.id === id);
//   if (index !== -1) {
//     worksData[index] = { ...worksData[index], ...JSON.parse(options.body) };
//     return {
//       code: 200,
//       msg: '修改成功',
//       data: worksData[index]
//     };
//   }
//   return {
//     code: 404,
//     msg: '作品不存在'
//   };
// });

// // 删除作品
// Mock.mock(new RegExp('/api/works/\\d+'), 'delete', (options) => {
//   const id = parseInt(options.url.match(/\/api\/works\/(\d+)/)[1]);
//   worksData = worksData.filter(w => w.id !== id);
//   return {
//     code: 200,
//     msg: '删除成功'
//   };
// });



//contract
let ContractData = [
  {
    id: 1,
    title: '测试合同1',
    start: '2017-08-13',
    finish: '2017-08-15',
    status: '已结束',
    link: 'baidu.com'
  },
  {
    id: 2,
    title: '测试合同2',
    start: '2019-08-13',
    finish: '2030-08-15',
    status: '有效',
    link: 'baidu.com'
  },
  {
    id: 3,
    title: '测试合同3',
    start: '2025-08-13',
    finish: '2039-08-15',
    status: '未确认',
    link: 'baidu.com'
  }
]

/*
Mock.mock('/getContractData','get',()=>{
  Result.data=ContractData;
  return Result;
})

Mock.mock('/addContract', 'post', (options) => {
  // 解析请求体
  const body = JSON.parse(options.body);
  
  // 生成新 ID (取当前最大 ID + 1)
  newId = 1;
  if(ContractData.length===0){
    newId = 1;
  }
  else{
    newId = Math.max(...ContractData.map(ContractData => ContractData.id)) + 1;
  }

  
  // 创建新合同对象
  const newContract = {
    id: newId,
    title: body.title,
    start: body.start,
    finish: body.finish,
    status: body.status,
    link: body.link
  };
  
  // 添加到合同列表
  ContractData.push(newContract);
  
  Result.msg = '添加合同成功';
  return Result;
});

Mock.mock(new RegExp('/updateContract/\\d+'), 'put', (options) => {
  // 获取合同 ID
  const id = parseInt(options.url.match(/\/updateContract\/(\d+)/)[1]);
  
  const body = JSON.parse(options.body);

  // 查找合同
  const index = ContractData.findIndex(ContractData => ContractData.id === id);
  
  if (index !== -1) {
    // 更新合同信息
    ContractData[index] = {
      id: ContractData[index].id,
      title: body.title,
      start: body.start,
      finish: body.finish,
      status: body.status,
      link: body.link
    };
    
    Result.msg = '修改合同成功';
  } else {
    Result.code = 404;
    Result.msg = '修改合同失败';
  }

  return Result
});

Mock.mock(new RegExp('/deleteContract/\\d+'), 'delete', (options) => {
  // 获取合同 ID
  const id = parseInt(options.url.match(/\/deleteContract\/(\d+)/)[1]);
  
  // 查找合同
  const index = ContractData.findIndex(ContractData => ContractData.id === id);
  
  if (index !== -1) {
    // 删除合同
    ContractData.splice(index, 1);
    Result.msg = '删除合同成功';
  } else {
    Result.code = 404;
    Result.msg = '未找到该合同';
  }
  
  return Result;
});
*/




//publicOpinion
let positiveComment = [
  12349,12398,24821,12381,24343,23345,12345,17890,18328,18881,23441,23441
]
let negativeComment = [
  15165,12312,12323,15521,16642,12333,24545,13223,24545,12223,15512,12344
]
let neutralComment = [
  12375,12095,12325,13665,16325,12425,12425,12355,13722,18873,10692,16532
]

let fans = [
  19652, 15873, 17748, 16578, 12376, 13504, 17291, 18460, 16236, 11180, 12590, 16278
]
let anonymous = [
  17354, 19280, 12400, 17429, 15282, 15883, 18483, 16965, 11237, 12789, 16098, 17758
]
let blacklist = [
  562, 665, 796, 865, 993, 1090, 1157, 1237, 1393, 1447, 1569, 1654
]

Mock.mock('/getCommentData','get',()=>{
  Result.data = {
    positiveComment: positiveComment,
    negativeComment: negativeComment,
    neutralComment: neutralComment
  }
  return Result;
})
Mock.mock('/getUserGroupData','get',()=>{
  Result.data = {
    fans: fans,
    anonymous: anonymous,
    blacklist: blacklist
  }
  return Result;
})


// 用户列表
let UserList=[
  {
      id:1,
      name:'豆豆',
      property:'系统管理员',
      propertyid:1,
      password:'123456'
  },
  {
      id:2,
      name:"咪咪",
      property:'公司高层',
      propertyid:2,
      password:'123456'
  },
  {
      id:3,
      name:"捏捏",
      property:'经纪人',
      propertyid:3,
      password:'123456'
  },
  {
      id:4,
      name:"杜冰儿",
      property:'艺人',
      propertyid:4,
      password:'123456'
  },
  {
      id:5,
      name:"杜飞儿",
      property:'经纪人管理员',
      propertyid:5,
      password:'123456'
  },
  {
      id:6,
      name:"杜雪儿",
      property:'场地管理员',
      propertyid:6,
      password:'123456'
  }
]

// Mock.mock('/getUserList','get',()=>{
//   Result.data=UserList;
//   return Result;
// })

// Mock.mock(new RegExp('/deleteUserList/\\d+'), 'delete', (options) => {
//   // 获取用户ID
//   const id = parseInt(options.url.match(/\/deleteUserList\/(\d+)/)[1]);
//
//   // 查找用户
//   const index = UserList.findIndex(User => User.id === id);
//
//   if (index !== -1) {
//     // 删除用户
//     UserList.splice(index, 1);
//     Result.msg = '删除行程成功';
//   } else {
//     Result.code = 404;
//     Result.msg = '未找到该行程';
//   }
//
//   return Result;
// });

// Mock.mock(new RegExp('/updateUserList/\\d+'), 'put', (options) => {
//   const id = parseInt(options.url.match(/\d+/)[0])
//   const body = JSON.parse(options.body)
//
//   // 查找并更新数据
//   const index = UserList.findIndex(item => item.id === id)
//   if (index !== -1) {
//     UserList[index] = {
//       ...UserList[index],
//       name: body.name,
//       property: body.property,
//       propertyid: body.propertyid,
//       password: body.password
//     }
//     return { code: 200, msg: '修改成功' }
//   }
//   return { code: 404, msg: '未找到该行程' }
// })



// Mock.mock('/addUserList', 'post', (options) => {
//   // 解析请求体
//   const body = JSON.parse(options.body);
//
//   // 生成新 ID (取当前最大 ID + 1)
//   const newId = Math.max(...UserList.map(User => User.id)) + 1;
//
//   // 创建新艺人对象
//   const newUser = {
//     id: newId,
//     name: body.name,
//     property: body.property,
//     propertyid:body.propertyid,
//     password:body.password
//   };
//
//   // 添加到艺人列表
//   UserList.push(newUser);
//
//   Result.msg = '添加艺人成功';
//   return Result;
// });

module.exports.artistInfo = artistInfo;